<?php
  // what platform are we looking at?
  $platform = isset( $_REQUEST['platform'] ) ? $_REQUEST['platform'] : '';
  //$platform="nerrs.nocrcmet.met,nerrs.nocrcwq.wq";

  $platform_list=split(',',$platform);
  foreach($platform_list as $plat){

  $o = file_get_contents("obs_out/152.20.240.19/html_contents//".$plat.".htm");
  //$o = file_get_contents("$plat.htm");

  
  if($plat=="nccoos.jpier.met"){
        $o=preg_replace("<\<hr/\>\<br/\>>","Jennette's Pier, NC<br>",$o);
  }  
  if($plat=="nccoos.jpier.adcp"){
        $o=preg_replace("<\<hr/\>\<br/\>>","ADCP data, NC<br>",$o);
  }  
  if($plat=="nccoos.stones.met"){
        $o=preg_replace("<\<hr/\>\<br/\>>","Stones Bay, New River, NC<br>",$o);
  }  
  if($plat=="nccoos.morgan.met"){
        $o=preg_replace("<\<hr/\>\<br/\>>","Morgan Bay, New River, NC<br>",$o);
  }  

  if($plat=="nerrs.acespwq.wq"){
      $o=preg_replace("<NERRS Station, ACE Basin, NC\<br/\>>","",$o);
  }  
  if($plat=="nerrs.acespwq.wq"){
      $o=preg_replace("<NERRS Station, ACE Basin, NC\<br/\>>","",$o);
  }  
  if($plat=="nerrs.acespwq.wq"){
      $o=preg_replace("<NERRS Station, ACE Basin, NC\<br/\>>","",$o);
  }  
  if($plat=="nerrs.nocrcwq.wq"){
      $o=preg_replace("<NERRS Station, Research Creek, NC\<br/\>>","",$o);
  }
  if($plat=="nerrs.niwolwq.wq"){
      $o=preg_replace("<NERRS Station, North Inlet Winyah Bay, SC\<br/\>>","",$o);
  }
  if($plat=="nerrs.acespwq.wq"){
      $o=preg_replace("<ACE Basin, SC\<br/\>>","",$o);
  }
  if($plat=="nerrs.niwolwq.wq"){
      $o=preg_replace("<North Inlet Winyah Bay, SC\<br/\>>","",$o);
  }
 
  if($plat=="nerrs.nocrcwq.wq"){
      $o=preg_replace("<Research Creek, NC\<br/\>>","",$o);
  }
  $o=preg_replace("<milliSiemens per centimeter>","mS/cm",$o);
  $o=preg_replace("<milligrams per liter>","mg/L",$o);
  $o=preg_replace("<\<caption\>>","",$o);
  $o=preg_replace("<\</caption\>>","<br>",$o);
  $o=preg_replace("<\<hr/\>>","",$o);
  $o=preg_replace("<\<tr\>\<th scope=\"row\"\>\</th\>\<td\>\</td\>\</tr\>>","",$o); 
  $o=preg_replace("<\</table\>>","",$o); 
  $pattern="<\<table cellpadding=\"2\" cellspacing=\"2\"\>>";
  $o=preg_replace($pattern,"",$o);
  $pattern="<\<tr\>\<th scope=\"row\"\>>"; 
  $o=preg_replace($pattern,"",$o);
  $pattern="<\</th\>\<td\>>"; 
  $o=preg_replace($pattern,": ",$o);
  $pattern="<\</td\>\</tr\>>"; 
  $o=preg_replace($pattern,"<br>",$o);
  $pattern="<\</a\>>"; 
  $o=preg_replace($pattern,"",$o);
  $pattern="<\<br/\>>"; 
  $o=preg_replace($pattern,"<br>",$o);

  $array1=split("<a href",$o);
  $pattern="/(.*)(Surface conditions as of )(.*)/";



  if(preg_match($pattern,$array1[0],$matches)){
     echo $matches[1];
     
     if(($plat=="nerrs.nocrcwq.wq")||($plat=="nerrs.niwolwq.wq")||($plat=="nerrs.acespwq.wq")){echo "Water Quality Data<br> ";}
     
     echo "Last update: ";
     echo $matches[3];
  }
  else {
     echo $array1[0];
  }
  for($i=1;$i<count($array1);$i++){
   $array2=split(">",$array1[$i]);
   for($j=1;$j<count($array2);$j++){
      echo "$array2[$j]";
      if(substr($array2[$j],-3)=="<br"){
         echo ">";
      }
      if(strpos($array2[$j],".png")){
          echo "?x=".rand().">"; 
      }
      if(substr($array2[$j],-5)=="</div"){
         echo ">";
      }
   }
  }
}
  
?>
